package test;

/**
 * @author 豆包LU
 * @date 2023/4/19 9:53
 */
import java.util.concurrent.TimeUnit;

public class WaitingTime {

    public static void main(String[] args) {
        WaitingTime waitingTime = new WaitingTime();
        waitingTime.startThread();
    }

    public void startThread() {
        Thread thread = new Thread(() -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(5); // 线程休眠5秒
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();

        while (true) {
            Thread.State state = thread.getState();
            System.out.println("Thread state: " + state);
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
